package com.ly.upload;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @program: ly-common
 * @description:
 * @author: 作者
 * @create: 2022-12-03 12:01
 */
@Configuration
@ComponentScan("com.ly.upload")
public class UploadApp implements WebMvcConfigurer {
    public static void main(String[] args) {
        SpringApplication.run(UploadApp.class, args);
    }

    @Value("${ly.upload.web-path}")
    private String webPath;

    @Value("${ly.upload.save-path}")
    private String savePath;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String spath = (savePath.startsWith("/") ? "" : "/") + savePath + (savePath.endsWith("/") ? "" : "/");
        String wpath = (webPath.startsWith("/") ? "" : "/") + webPath + (webPath.endsWith("/") ? "" : "/");
        registry.addResourceHandler(wpath + "**")
                .addResourceLocations("file:" + spath)
                .addResourceLocations("classpath:static/upload/");
    }
}
